﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DOAN.Public;

namespace DOAN.DLL
{
    public class HoaDonDAL
    {
        ClsConnection cls;

        public HoaDonDAL()
        {
            cls = new ClsConnection();
        }

        public DataTable Load()
        {
            return cls.GetData("HOADON_LOAD");
        }

        public int Insert(HoaDonPublic p)
        {
            int Nparameter = 6;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaHoaDon";
            name[1] = "@MaHopDong";
            name[2] = "@NgayInHoaDon";
            name[3] = "@TongTien";
            name[4] = "@NgayThanhToan";
            name[5] = "@HoaDon_Id";

            value[0] = p.MaHoaDon;
            value[1] = p.MaHopDong;
            value[2] = p.NgayInHoaDon;
            value[3] = p.TongTien;
            value[4] = p.NgayThanhToan;
            value[5] = p.HoaDon_Id;

            return cls.UpdateData("HOADON_INSERT", name, value, Nparameter);
        }

        public int Update(HoaDonPublic p)
        {
            int Nparameter = 6;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaHoaDon";
            name[1] = "@MaHopDong";
            name[2] = "@NgayInHoaDon";
            name[3] = "@TongTien";
            name[4] = "@NgayThanhToan";
            name[5] = "@HoaDon_Id";

            value[0] = p.MaHoaDon;
            value[1] = p.MaHopDong;
            value[2] = p.NgayInHoaDon;
            value[3] = p.TongTien;
            value[4] = p.NgayThanhToan;
            value[5] = p.HoaDon_Id;

            return cls.UpdateData("HOADON_UPDATE", name, value, Nparameter);
        }

        public int Delete(HoaDonPublic p)
        {
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaHoaDon";
            value[0] = p.MaHoaDon;
            return cls.UpdateData("HOADON_DELETE", name, value, Nparameter);
        }
    }
}
